//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2011 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _BUOLA_UTILITY_CCURSORPOS_H_
#define _BUOLA_UTILITY_CCURSORPOS_H_

#include <buola/buola.h>
#include <buola/utility/operators.h>

namespace buola {

///\addtogroup utility
///@{
    
/////////////////////////////////////////////////////////////////////////////////////////////////

/// cursor position

/// This class is used in different points of the library to hold a cursor position, consisting
/// of a row and a column.
///
/////////////////////////////////////////////////////////////////////////////////////////////////
    
class CCursorPos : public ops::UComparison<CCursorPos>
{
public:
    ///default constructor (sets to 0,0)
    CCursorPos()
        :   r(0)
        ,   c(0)
    {}

    ///initializes to \p pr and \p pc
    CCursorPos(int pr,int pc)
        :   r(pr)
        ,   c(pc)
    {}
    
    ///sets the value to \p pr and \p pc
    void Set(int pr,int pc)
    {
        r=pr;
        c=pc;
    }

    ///copy constructor (defaulted)
    CCursorPos(const CCursorPos&)=default;

    ///returns true if this cursor position is before \p pOther
    
    ///A cursor position is considered to be before if it is in a lower row or the row is the same and
    ///it is in a lower column.
    bool operator<(const CCursorPos &pOther) const
    {
        return(r<pOther.r||(r==pOther.r&&c<pOther.c));
    }

    ///returns true if this cursor position is equal to \p pOther
    bool operator==(const CCursorPos &pOther) const
    {
        return(r==pOther.r&&c==pOther.c);
    }

    ///assignment operator (defaulted)
    CCursorPos &operator=(const CCursorPos&)=default;

    int r;  ///< row
    int c;  ///< column
};

///@}

/*namespace buola*/ }

#endif
